SlideShare a Scribd company logo
Class No.16  Data Structures http://ecomputernotes.com
Deleting a node in BST ,[object Object],[object Object],[object Object],http://ecomputernotes.com
Deleting a node in BST ,[object Object],6 2 4 3 1 8 http://ecomputernotes.com
Deleting a node in BST ,[object Object],6 2 4 3 1 8 6 2 4 3 1 8  http://ecomputernotes.com
Deleting a node in BST ,[object Object],6 2 4 3 1 8 6 2 4 3 1 8 6 2 3 1 8   http://ecomputernotes.com
Deleting a node in BST ,[object Object],[object Object],http://ecomputernotes.com
Deleting a node in BST Delete(2): locate inorder successor 6 2 5 3 1 8 4 Inorder  successor http://ecomputernotes.com
Deleting a node in BST Delete(2): locate inorder successor 6 2 5 3 1 8 4 Inorder  successor ,[object Object],[object Object],http://ecomputernotes.com
Deleting a node in BST Delete(2): copy data from inorder successor 6 2 5 3 1 8 4  6 3 5 3 1 8 4 http://ecomputernotes.com
Deleting a node in BST Delete(2): remove the inorder successor 6 2 5 3 1 8 4  6 3 5 3 1 8 4  6 3 5 3 1 8 4 http://ecomputernotes.com
Deleting a node in BST Delete(2)  6 3 5 4 1 8  6 3 5 3 1 8 4 http://ecomputernotes.com
C++ code for delete ,[object Object],[object Object],http://ecomputernotes.com
C++ code for delete TreeNode<int>* remove(TreeNode<int>* tree, int info) { TreeNode<int>* t; int cmp = info - *(tree->getInfo()); if( cmp < 0 ){ t = remove(tree->getLeft(), info); tree->setLeft( t ); } else if( cmp > 0 ){ t = remove(tree->getRight(), info); tree->setRight( t ); }  http://ecomputernotes.com
C++ code for delete TreeNode<int>* remove(TreeNode<int>* tree, int info) { TreeNode<int>* t; int cmp = info - *(tree->getInfo()); if( cmp < 0 ){ t = remove(tree->getLeft(), info); tree->setLeft( t ); } else if( cmp > 0 ){ t = remove(tree->getRight(), info); tree->setRight( t ); }  http://ecomputernotes.com
C++ code for delete TreeNode<int>* remove(TreeNode<int>* tree, int info) { TreeNode<int>* t; int cmp = info - *(tree->getInfo()); if( cmp < 0 ){ t = remove(tree->getLeft(), info); tree->setLeft( t ); } else if( cmp > 0 ){ t = remove(tree->getRight(), info); tree->setRight( t ); }  http://ecomputernotes.com
C++ code for delete TreeNode<int>* remove(TreeNode<int>* tree, int info) { TreeNode<int>* t; int cmp = info - *(tree->getInfo()); if( cmp < 0 ){ t = remove(tree->getLeft(), info); tree->setLeft( t ); } else if( cmp > 0 ){ t = remove(tree->getRight(), info); tree->setRight( t ); }  http://ecomputernotes.com
C++ code for delete //two children, replace with inorder successor else if(tree->getLeft() != NULL  && tree->getRight() != NULL ){  TreeNode<int>* minNode; minNode = findMin(tree->getRight()); tree->setInfo( minNode->getInfo() ); t = remove(tree->getRight(), *(minNode->getInfo())); tree->setRight( t ); }  http://ecomputernotes.com
C++ code for delete //two children, replace with inorder successor else if(tree->getLeft() != NULL  && tree->getRight() != NULL ){  TreeNode<int>* minNode; minNode = findMin(tree->getRight()); tree->setInfo( minNode->getInfo() ); t = remove(tree->getRight(), *(minNode->getInfo())); tree->setRight( t ); }  http://ecomputernotes.com
C++ code for delete //two children, replace with inorder successor else if(tree->getLeft() != NULL  && tree->getRight() != NULL ){  TreeNode<int>* minNode; minNode = findMin(tree->getRight()); tree->setInfo( minNode->getInfo() ); t = remove(tree->getRight(), *(minNode->getInfo())); tree->setRight( t ); }  http://ecomputernotes.com
C++ code for delete //two children, replace with inorder successor else if(tree->getLeft() != NULL  && tree->getRight() != NULL ){  TreeNode<int>* minNode; minNode = findMin(tree->getRight()); tree->setInfo( minNode->getInfo() ); t = remove(tree->getRight(), *(minNode->getInfo())); tree->setRight( t ); }  http://ecomputernotes.com
C++ code for delete //two children, replace with inorder successor else if(tree->getLeft() != NULL  && tree->getRight() != NULL ){  TreeNode<int>* minNode; minNode = findMin(tree->getRight()); tree->setInfo( minNode->getInfo() ); t = remove(tree->getRight(), *(minNode->getInfo())); tree->setRight( t ); }  http://ecomputernotes.com
C++ code for delete else { //  case 1 TreeNode<int>* nodeToDelete = tree; if( tree->getLeft() == NULL )  // will handle 0 children tree = tree->getRight();  else if( tree->getRight() == NULL ) tree = tree->getLeft(); else tree = NULL;  delete nodeToDelete; } return tree; }  http://ecomputernotes.com
C++ code for delete else { //  case 1 TreeNode<int>* nodeToDelete = tree; if( tree->getLeft() == NULL )  // will handle 0 children tree = tree->getRight();  else if( tree->getRight() == NULL ) tree = tree->getLeft(); else tree = NULL;  delete nodeToDelete; } return tree; }  http://ecomputernotes.com
C++ code for delete else { //  case 1 TreeNode<int>* nodeToDelete = tree; if( tree->getLeft() == NULL )  // will handle 0 children tree = tree->getRight();  else if( tree->getRight() == NULL ) tree = tree->getLeft(); else tree = NULL;  delete nodeToDelete; } return tree; }  http://ecomputernotes.com
C++ code for delete TreeNode<int>* findMin(TreeNode<int>* tree) { if( tree == NULL )  return NULL; if( tree->getLeft() == NULL )  return tree; //  this is it. return findMin( tree->getLeft() ); }  http://ecomputernotes.com
C++ code for delete TreeNode<int>* findMin(TreeNode<int>* tree) { if( tree == NULL )  return NULL; if( tree->getLeft() == NULL )  return tree; //  this is it. return findMin( tree->getLeft() ); }  http://ecomputernotes.com
C++ code for delete TreeNode<int>* findMin(TreeNode<int>* tree) { if( tree == NULL )  return NULL; if( tree->getLeft() == NULL )  return tree; //  this is it. return findMin( tree->getLeft() ); }  http://ecomputernotes.com
BinarySearchTree.h Let us design the BinarySearchTree class (factory). http://ecomputernotes.com
BinarySearchTree.h #ifndef _BINARY_SEARCH_TREE_H_ #define _BINARY_SEARCH_TREE_H_ #include <iostream.h> // For NULL // Binary node and forward declaration template <class EType> class BinarySearchTree;  http://ecomputernotes.com
BinarySearchTree.h #ifndef _BINARY_SEARCH_TREE_H_ #define _BINARY_SEARCH_TREE_H_ #include <iostream.h> // For NULL // Binary node and forward declaration template <class EType> class BinarySearchTree;  http://ecomputernotes.com
BinarySearchTree.h template <class EType> class BinaryNode { EType element; BinaryNode *left; BinaryNode *right; BinaryNode( const EType & theElement,  BinaryNode *lt, BinaryNode *rt ) : element( theElement ), left( lt ),  right( rt ) { } friend class BinarySearchTree<EType>; };  http://ecomputernotes.com
BinarySearchTree.h template <class EType> class BinaryNode { EType element; BinaryNode *left; BinaryNode *right; BinaryNode( const EType & theElement,  BinaryNode *lt, BinaryNode *rt ) : element( theElement ), left( lt ),  right( rt ) { } friend class BinarySearchTree<EType>; };  http://ecomputernotes.com
BinarySearchTree.h template <class EType> class BinaryNode { EType element; BinaryNode *left; BinaryNode *right; BinaryNode( const EType & theElement,  BinaryNode *lt, BinaryNode *rt ) : element( theElement ), left( lt ),  right( rt ) { } friend class BinarySearchTree<EType>; };  http://ecomputernotes.com
BinarySearchTree.h template <class EType> class BinaryNode { EType element; BinaryNode *left; BinaryNode *right; BinaryNode( const EType & theElement,  BinaryNode *lt, BinaryNode *rt ) : element( theElement ), left( lt ),  right( rt ) { } friend class BinarySearchTree<EType>; };  http://ecomputernotes.com
BinarySearchTree.h template <class EType> class BinarySearchTree { public: BinarySearchTree( const EType& notFound ); BinarySearchTree( const BinarySearchTree& rhs ); ~BinarySearchTree( ); const EType& findMin( ) const; const EType& findMax( ) const; const EType& find( const EType & x ) const; bool isEmpty( ) const; void printInorder( ) const; http://ecomputernotes.com
BinarySearchTree.h void insert( const EType& x ); void remove( const EType& x ); const BinarySearchTree & operator= ( const BinarySearchTree & rhs ); http://ecomputernotes.com
BinarySearchTree.h private: BinaryNode<EType>* root; // ITEM_NOT_FOUND object used to signal failed finds const EType ITEM_NOT_FOUND; const EType& elementAt( BinaryNode<EType>* t ); void insert(const EType& x, BinaryNode<EType>* & t); void remove(const EType& x, BinaryNode<EType>* & t); BinaryNode<EType>* findMin(BinaryNode<EType>* t); BinaryNode<EType>* findMax(BinaryNode<EType>* t); BinaryNode<EType>* find(const EType& x, BinaryNode<EType>* t ); void makeEmpty(BinaryNode<EType>* & t); void printInorder(BinaryNode<EType>* t); }; #endif http://ecomputernotes.com

More Related Content

What's hot

CS323: Binary Search Trees
CS323: Binary Search TreesCS323: Binary Search Trees
CS323: Binary Search Trees
Jinho Choi
 
Game in ex
Game in exGame in ex
Game in ex
Vitor Santos
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
Namgee Lee
 
Regression and Classification with R
Regression and Classification with RRegression and Classification with R
Regression and Classification with R
Yanchang Zhao
 
CS323: Sort - Distribution-based
CS323: Sort - Distribution-basedCS323: Sort - Distribution-based
CS323: Sort - Distribution-based
Jinho Choi
 
CS323: Trie
CS323: TrieCS323: Trie
CS323: Trie
Jinho Choi
 
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev FedorProgramming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
Fedor Lavrentyev
 
手把手教你 R 語言分析實務
手把手教你 R 語言分析實務手把手教你 R 語言分析實務
手把手教你 R 語言分析實務
Helen Chang
 
Python Peculiarities
Python PeculiaritiesPython Peculiarities
Python Peculiarities
noamt
 
Oop 1
Oop 1Oop 1
Java Basics - Part1
Java Basics - Part1Java Basics - Part1
Java Basics - Part1
Vani Kandhasamy
 
CS323: Balanced Binary Search Trees
CS323: Balanced Binary Search TreesCS323: Balanced Binary Search Trees
CS323: Balanced Binary Search Trees
Jinho Choi
 

What's hot (12)

CS323: Binary Search Trees
CS323: Binary Search TreesCS323: Binary Search Trees
CS323: Binary Search Trees
 
Game in ex
Game in exGame in ex
Game in ex
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
 
Regression and Classification with R
Regression and Classification with RRegression and Classification with R
Regression and Classification with R
 
CS323: Sort - Distribution-based
CS323: Sort - Distribution-basedCS323: Sort - Distribution-based
CS323: Sort - Distribution-based
 
CS323: Trie
CS323: TrieCS323: Trie
CS323: Trie
 
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev FedorProgramming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
 
手把手教你 R 語言分析實務
手把手教你 R 語言分析實務手把手教你 R 語言分析實務
手把手教你 R 語言分析實務
 
Python Peculiarities
Python PeculiaritiesPython Peculiarities
Python Peculiarities
 
Oop 1
Oop 1Oop 1
Oop 1
 
Java Basics - Part1
Java Basics - Part1Java Basics - Part1
Java Basics - Part1
 
CS323: Balanced Binary Search Trees
CS323: Balanced Binary Search TreesCS323: Balanced Binary Search Trees
CS323: Balanced Binary Search Trees
 

Viewers also liked

computer notes - Data Structures - 25
computer notes - Data Structures - 25computer notes - Data Structures - 25
computer notes - Data Structures - 25
ecomputernotes
 
computer notes - Data Structures - 23
computer notes - Data Structures - 23computer notes - Data Structures - 23
computer notes - Data Structures - 23
ecomputernotes
 
computer notes - Data Structures - 1
computer notes - Data Structures - 1computer notes - Data Structures - 1
computer notes - Data Structures - 1
ecomputernotes
 
computer notes - Data Structures - 18
computer notes - Data Structures - 18computer notes - Data Structures - 18
computer notes - Data Structures - 18
ecomputernotes
 
computer notes - Data Structures - 6
computer notes - Data Structures - 6computer notes - Data Structures - 6
computer notes - Data Structures - 6
ecomputernotes
 
computer notes - Data Structures - 21
computer notes - Data Structures - 21computer notes - Data Structures - 21
computer notes - Data Structures - 21
ecomputernotes
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36
ecomputernotes
 
computer notes - Data Structures - 37
computer notes - Data Structures - 37computer notes - Data Structures - 37
computer notes - Data Structures - 37
ecomputernotes
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32
ecomputernotes
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4
ecomputernotes
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
ecomputernotes
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3
ecomputernotes
 
computer notes - Data Structures - 10
computer notes - Data Structures - 10computer notes - Data Structures - 10
computer notes - Data Structures - 10
ecomputernotes
 
computer notes - Data Structures - 15
computer notes - Data Structures - 15computer notes - Data Structures - 15
computer notes - Data Structures - 15
ecomputernotes
 
computer notes - Data Structures - 29
computer notes - Data Structures - 29computer notes - Data Structures - 29
computer notes - Data Structures - 29
ecomputernotes
 
computer notes - Data Structures - 39
computer notes - Data Structures - 39computer notes - Data Structures - 39
computer notes - Data Structures - 39
ecomputernotes
 
computer notes - Data Structures - 38
computer notes - Data Structures - 38computer notes - Data Structures - 38
computer notes - Data Structures - 38
ecomputernotes
 
computer notes - Data Structures - 33
computer notes - Data Structures - 33computer notes - Data Structures - 33
computer notes - Data Structures - 33
ecomputernotes
 
computer notes - Data Structures - 5
computer notes - Data Structures - 5computer notes - Data Structures - 5
computer notes - Data Structures - 5
ecomputernotes
 
computer notes - Data Structures - 17
computer notes - Data Structures - 17computer notes - Data Structures - 17
computer notes - Data Structures - 17
ecomputernotes
 

Viewers also liked (20)

computer notes - Data Structures - 25
computer notes - Data Structures - 25computer notes - Data Structures - 25
computer notes - Data Structures - 25
 
computer notes - Data Structures - 23
computer notes - Data Structures - 23computer notes - Data Structures - 23
computer notes - Data Structures - 23
 
computer notes - Data Structures - 1
computer notes - Data Structures - 1computer notes - Data Structures - 1
computer notes - Data Structures - 1
 
computer notes - Data Structures - 18
computer notes - Data Structures - 18computer notes - Data Structures - 18
computer notes - Data Structures - 18
 
computer notes - Data Structures - 6
computer notes - Data Structures - 6computer notes - Data Structures - 6
computer notes - Data Structures - 6
 
computer notes - Data Structures - 21
computer notes - Data Structures - 21computer notes - Data Structures - 21
computer notes - Data Structures - 21
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36
 
computer notes - Data Structures - 37
computer notes - Data Structures - 37computer notes - Data Structures - 37
computer notes - Data Structures - 37
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3
 
computer notes - Data Structures - 10
computer notes - Data Structures - 10computer notes - Data Structures - 10
computer notes - Data Structures - 10
 
computer notes - Data Structures - 15
computer notes - Data Structures - 15computer notes - Data Structures - 15
computer notes - Data Structures - 15
 
computer notes - Data Structures - 29
computer notes - Data Structures - 29computer notes - Data Structures - 29
computer notes - Data Structures - 29
 
computer notes - Data Structures - 39
computer notes - Data Structures - 39computer notes - Data Structures - 39
computer notes - Data Structures - 39
 
computer notes - Data Structures - 38
computer notes - Data Structures - 38computer notes - Data Structures - 38
computer notes - Data Structures - 38
 
computer notes - Data Structures - 33
computer notes - Data Structures - 33computer notes - Data Structures - 33
computer notes - Data Structures - 33
 
computer notes - Data Structures - 5
computer notes - Data Structures - 5computer notes - Data Structures - 5
computer notes - Data Structures - 5
 
computer notes - Data Structures - 17
computer notes - Data Structures - 17computer notes - Data Structures - 17
computer notes - Data Structures - 17
 

Similar to computer notes - Data Structures - 16

Data structures lecture 04
Data structures  lecture 04Data structures  lecture 04
Data structures lecture 04
Nazir Ahmed
 
For this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docxFor this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docx
budbarber38650
 
Bsides
BsidesBsides
Bsides
m j
 
C++: inheritance, composition, polymorphism
C++: inheritance, composition, polymorphismC++: inheritance, composition, polymorphism
C++: inheritance, composition, polymorphism
Jussi Pohjolainen
 
Computer notes data structures - 9
Computer notes   data structures - 9Computer notes   data structures - 9
Computer notes data structures - 9
ecomputernotes
 
(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers
Carlo Pescio
 
Python Objects
Python ObjectsPython Objects
Python Objects
Quintagroup
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
shanki7
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
michardsonkhaicarr37
 
To create a node for a binary search tree (BTNode, ) and to create a .pdf
To create a node for a binary search tree (BTNode, ) and to create a .pdfTo create a node for a binary search tree (BTNode, ) and to create a .pdf
To create a node for a binary search tree (BTNode, ) and to create a .pdf
bhim1213
 
Write a C++ function to delete the given value from the binary search.docx
Write a C++ function to delete the given value from the binary search.docxWrite a C++ function to delete the given value from the binary search.docx
Write a C++ function to delete the given value from the binary search.docx
noreendchesterton753
 
Computer notes - Sorting
Computer notes  - SortingComputer notes  - Sorting
Computer notes - Sorting
ecomputernotes
 
Move Accumulation To Collecting Parameter
Move Accumulation To Collecting ParameterMove Accumulation To Collecting Parameter
Move Accumulation To Collecting Parameter
melbournepatterns
 
Stop Monkeys Fall
Stop Monkeys FallStop Monkeys Fall
Stop Monkeys Fall
Hajime Morrita
 
002207866
002207866002207866
Computer notes - Binary Search Tree with Strings
Computer notes - Binary Search Tree with Strings Computer notes - Binary Search Tree with Strings
Computer notes - Binary Search Tree with Strings
ecomputernotes
 
Exception Handling1
Exception Handling1Exception Handling1
Exception Handling1
guest739536
 
create a binary search tree from an empty one by adding the key valu.pdf
create a binary search tree from an empty one by adding the key valu.pdfcreate a binary search tree from an empty one by adding the key valu.pdf
create a binary search tree from an empty one by adding the key valu.pdf
erremmfab
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
greenwop
 
Antlr V3
Antlr V3Antlr V3
Antlr V3
guest5024494
 

Similar to computer notes - Data Structures - 16 (20)

Data structures lecture 04
Data structures  lecture 04Data structures  lecture 04
Data structures lecture 04
 
For this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docxFor this project, write a program that stores integers in a binary.docx
For this project, write a program that stores integers in a binary.docx
 
Bsides
BsidesBsides
Bsides
 
C++: inheritance, composition, polymorphism
C++: inheritance, composition, polymorphismC++: inheritance, composition, polymorphism
C++: inheritance, composition, polymorphism
 
Computer notes data structures - 9
Computer notes   data structures - 9Computer notes   data structures - 9
Computer notes data structures - 9
 
(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers
 
Python Objects
Python ObjectsPython Objects
Python Objects
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
To create a node for a binary search tree (BTNode, ) and to create a .pdf
To create a node for a binary search tree (BTNode, ) and to create a .pdfTo create a node for a binary search tree (BTNode, ) and to create a .pdf
To create a node for a binary search tree (BTNode, ) and to create a .pdf
 
Write a C++ function to delete the given value from the binary search.docx
Write a C++ function to delete the given value from the binary search.docxWrite a C++ function to delete the given value from the binary search.docx
Write a C++ function to delete the given value from the binary search.docx
 
Computer notes - Sorting
Computer notes  - SortingComputer notes  - Sorting
Computer notes - Sorting
 
Move Accumulation To Collecting Parameter
Move Accumulation To Collecting ParameterMove Accumulation To Collecting Parameter
Move Accumulation To Collecting Parameter
 
Stop Monkeys Fall
Stop Monkeys FallStop Monkeys Fall
Stop Monkeys Fall
 
002207866
002207866002207866
002207866
 
Computer notes - Binary Search Tree with Strings
Computer notes - Binary Search Tree with Strings Computer notes - Binary Search Tree with Strings
Computer notes - Binary Search Tree with Strings
 
Exception Handling1
Exception Handling1Exception Handling1
Exception Handling1
 
create a binary search tree from an empty one by adding the key valu.pdf
create a binary search tree from an empty one by adding the key valu.pdfcreate a binary search tree from an empty one by adding the key valu.pdf
create a binary search tree from an empty one by adding the key valu.pdf
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
Antlr V3
Antlr V3Antlr V3
Antlr V3
 

More from ecomputernotes

computer notes - Data Structures - 30
computer notes - Data Structures - 30computer notes - Data Structures - 30
computer notes - Data Structures - 30
ecomputernotes
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11
ecomputernotes
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20
ecomputernotes
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraintsecomputernotes
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functionsecomputernotes
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueriesecomputernotes
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objectsecomputernotes
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28
ecomputernotes
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19
ecomputernotes
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31
ecomputernotes
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueriesecomputernotes
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functionsecomputernotes
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22
ecomputernotes
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35
ecomputernotes
 
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY ClauseComputer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY Clauseecomputernotes
 
Computer notes - Manipulating Data
Computer notes - Manipulating DataComputer notes - Manipulating Data
Computer notes - Manipulating Dataecomputernotes
 
Computer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT StatementsComputer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT Statementsecomputernotes
 
computer notes - Data Structures - 14
computer notes - Data Structures - 14computer notes - Data Structures - 14
computer notes - Data Structures - 14
ecomputernotes
 
Computer notes - Controlling User Access
Computer notes - Controlling User AccessComputer notes - Controlling User Access
Computer notes - Controlling User Accessecomputernotes
 
Computer notes - Using SET Operator
Computer notes - Using SET OperatorComputer notes - Using SET Operator
Computer notes - Using SET Operatorecomputernotes
 

More from ecomputernotes (20)

computer notes - Data Structures - 30
computer notes - Data Structures - 30computer notes - Data Structures - 30
computer notes - Data Structures - 30
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraints
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functions
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueries
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objects
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueries
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functions
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35
 
Computer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY ClauseComputer notes - Enhancements to the GROUP BY Clause
Computer notes - Enhancements to the GROUP BY Clause
 
Computer notes - Manipulating Data
Computer notes - Manipulating DataComputer notes - Manipulating Data
Computer notes - Manipulating Data
 
Computer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT StatementsComputer notes - Writing Basic SQL SELECT Statements
Computer notes - Writing Basic SQL SELECT Statements
 
computer notes - Data Structures - 14
computer notes - Data Structures - 14computer notes - Data Structures - 14
computer notes - Data Structures - 14
 
Computer notes - Controlling User Access
Computer notes - Controlling User AccessComputer notes - Controlling User Access
Computer notes - Controlling User Access
 
Computer notes - Using SET Operator
Computer notes - Using SET OperatorComputer notes - Using SET Operator
Computer notes - Using SET Operator
 

Recently uploaded

LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024
Lital Barkan
 
Authentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto RicoAuthentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto Rico
Corey Perlman, Social Media Speaker and Consultant
 
amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05
marketing317746
 
Organizational Change Leadership Agile Tour Geneve 2024
Organizational Change Leadership Agile Tour Geneve 2024Organizational Change Leadership Agile Tour Geneve 2024
Organizational Change Leadership Agile Tour Geneve 2024
Kirill Klimov
 
buy old yahoo accounts buy yahoo accounts
buy old yahoo accounts buy yahoo accountsbuy old yahoo accounts buy yahoo accounts
buy old yahoo accounts buy yahoo accounts
Susan Laney
 
Building Your Employer Brand with Social Media
Building Your Employer Brand with Social MediaBuilding Your Employer Brand with Social Media
Building Your Employer Brand with Social Media
LuanWise
 
Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024
FelixPerez547899
 
Lundin Gold Corporate Presentation - June 2024
Lundin Gold Corporate Presentation - June 2024Lundin Gold Corporate Presentation - June 2024
Lundin Gold Corporate Presentation - June 2024
Adnet Communications
 
Top mailing list providers in the USA.pptx
Top mailing list providers in the USA.pptxTop mailing list providers in the USA.pptx
Top mailing list providers in the USA.pptx
JeremyPeirce1
 
How MJ Global Leads the Packaging Industry.pdf
How MJ Global Leads the Packaging Industry.pdfHow MJ Global Leads the Packaging Industry.pdf
How MJ Global Leads the Packaging Industry.pdf
MJ Global
 
The Evolution and Impact of OTT Platforms: A Deep Dive into the Future of Ent...
The Evolution and Impact of OTT Platforms: A Deep Dive into the Future of Ent...The Evolution and Impact of OTT Platforms: A Deep Dive into the Future of Ent...
The Evolution and Impact of OTT Platforms: A Deep Dive into the Future of Ent...
ABHILASH DUTTA
 
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdfikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
agatadrynko
 
Mastering B2B Payments Webinar from BlueSnap
Mastering B2B Payments Webinar from BlueSnapMastering B2B Payments Webinar from BlueSnap
Mastering B2B Payments Webinar from BlueSnap
Norma Mushkat Gaffin
 
Income Tax exemption for Start up : Section 80 IAC
Income Tax  exemption for Start up : Section 80 IACIncome Tax  exemption for Start up : Section 80 IAC
Income Tax exemption for Start up : Section 80 IAC
CA Dr. Prithvi Ranjan Parhi
 
Authentically Social Presented by Corey Perlman
Authentically Social Presented by Corey PerlmanAuthentically Social Presented by Corey Perlman
Authentically Social Presented by Corey Perlman
Corey Perlman, Social Media Speaker and Consultant
 
Best Forex Brokers Comparison in INDIA 2024
Best Forex Brokers Comparison in INDIA 2024Best Forex Brokers Comparison in INDIA 2024
Best Forex Brokers Comparison in INDIA 2024
Top Forex Brokers Review
 
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s DholeraTata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Avirahi City Dholera
 
Creative Web Design Company in Singapore
Creative Web Design Company in SingaporeCreative Web Design Company in Singapore
Creative Web Design Company in Singapore
techboxsqauremedia
 
The 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdf
The 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdfThe 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdf
The 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdf
thesiliconleaders
 
Zodiac Signs and Food Preferences_ What Your Sign Says About Your Taste
Zodiac Signs and Food Preferences_ What Your Sign Says About Your TasteZodiac Signs and Food Preferences_ What Your Sign Says About Your Taste
Zodiac Signs and Food Preferences_ What Your Sign Says About Your Taste
my Pandit
 

Recently uploaded (20)

LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024
 
Authentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto RicoAuthentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto Rico
 
amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05amptalk_RecruitingDeck_english_2024.06.05
amptalk_RecruitingDeck_english_2024.06.05
 
Organizational Change Leadership Agile Tour Geneve 2024
Organizational Change Leadership Agile Tour Geneve 2024Organizational Change Leadership Agile Tour Geneve 2024
Organizational Change Leadership Agile Tour Geneve 2024
 
buy old yahoo accounts buy yahoo accounts
buy old yahoo accounts buy yahoo accountsbuy old yahoo accounts buy yahoo accounts
buy old yahoo accounts buy yahoo accounts
 
Building Your Employer Brand with Social Media
Building Your Employer Brand with Social MediaBuilding Your Employer Brand with Social Media
Building Your Employer Brand with Social Media
 
Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024
 
Lundin Gold Corporate Presentation - June 2024
Lundin Gold Corporate Presentation - June 2024Lundin Gold Corporate Presentation - June 2024
Lundin Gold Corporate Presentation - June 2024
 
Top mailing list providers in the USA.pptx
Top mailing list providers in the USA.pptxTop mailing list providers in the USA.pptx
Top mailing list providers in the USA.pptx
 
How MJ Global Leads the Packaging Industry.pdf
How MJ Global Leads the Packaging Industry.pdfHow MJ Global Leads the Packaging Industry.pdf
How MJ Global Leads the Packaging Industry.pdf
 
The Evolution and Impact of OTT Platforms: A Deep Dive into the Future of Ent...
The Evolution and Impact of OTT Platforms: A Deep Dive into the Future of Ent...The Evolution and Impact of OTT Platforms: A Deep Dive into the Future of Ent...
The Evolution and Impact of OTT Platforms: A Deep Dive into the Future of Ent...
 
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdfikea_woodgreen_petscharity_cat-alogue_digital.pdf
ikea_woodgreen_petscharity_cat-alogue_digital.pdf
 
Mastering B2B Payments Webinar from BlueSnap
Mastering B2B Payments Webinar from BlueSnapMastering B2B Payments Webinar from BlueSnap
Mastering B2B Payments Webinar from BlueSnap
 
Income Tax exemption for Start up : Section 80 IAC
Income Tax  exemption for Start up : Section 80 IACIncome Tax  exemption for Start up : Section 80 IAC
Income Tax exemption for Start up : Section 80 IAC
 
Authentically Social Presented by Corey Perlman
Authentically Social Presented by Corey PerlmanAuthentically Social Presented by Corey Perlman
Authentically Social Presented by Corey Perlman
 
Best Forex Brokers Comparison in INDIA 2024
Best Forex Brokers Comparison in INDIA 2024Best Forex Brokers Comparison in INDIA 2024
Best Forex Brokers Comparison in INDIA 2024
 
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s DholeraTata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
Tata Group Dials Taiwan for Its Chipmaking Ambition in Gujarat’s Dholera
 
Creative Web Design Company in Singapore
Creative Web Design Company in SingaporeCreative Web Design Company in Singapore
Creative Web Design Company in Singapore
 
The 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdf
The 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdfThe 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdf
The 10 Most Influential Leaders Guiding Corporate Evolution, 2024.pdf
 
Zodiac Signs and Food Preferences_ What Your Sign Says About Your Taste
Zodiac Signs and Food Preferences_ What Your Sign Says About Your TasteZodiac Signs and Food Preferences_ What Your Sign Says About Your Taste
Zodiac Signs and Food Preferences_ What Your Sign Says About Your Taste
 

computer notes - Data Structures - 16

  • 1. Class No.16 Data Structures http://ecomputernotes.com
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. Deleting a node in BST Delete(2): locate inorder successor 6 2 5 3 1 8 4 Inorder successor http://ecomputernotes.com
  • 8.
  • 9. Deleting a node in BST Delete(2): copy data from inorder successor 6 2 5 3 1 8 4  6 3 5 3 1 8 4 http://ecomputernotes.com
  • 10. Deleting a node in BST Delete(2): remove the inorder successor 6 2 5 3 1 8 4  6 3 5 3 1 8 4  6 3 5 3 1 8 4 http://ecomputernotes.com
  • 11. Deleting a node in BST Delete(2)  6 3 5 4 1 8  6 3 5 3 1 8 4 http://ecomputernotes.com
  • 12.
  • 13. C++ code for delete TreeNode<int>* remove(TreeNode<int>* tree, int info) { TreeNode<int>* t; int cmp = info - *(tree->getInfo()); if( cmp < 0 ){ t = remove(tree->getLeft(), info); tree->setLeft( t ); } else if( cmp > 0 ){ t = remove(tree->getRight(), info); tree->setRight( t ); }  http://ecomputernotes.com
  • 14. C++ code for delete TreeNode<int>* remove(TreeNode<int>* tree, int info) { TreeNode<int>* t; int cmp = info - *(tree->getInfo()); if( cmp < 0 ){ t = remove(tree->getLeft(), info); tree->setLeft( t ); } else if( cmp > 0 ){ t = remove(tree->getRight(), info); tree->setRight( t ); }  http://ecomputernotes.com
  • 15. C++ code for delete TreeNode<int>* remove(TreeNode<int>* tree, int info) { TreeNode<int>* t; int cmp = info - *(tree->getInfo()); if( cmp < 0 ){ t = remove(tree->getLeft(), info); tree->setLeft( t ); } else if( cmp > 0 ){ t = remove(tree->getRight(), info); tree->setRight( t ); }  http://ecomputernotes.com
  • 16. C++ code for delete TreeNode<int>* remove(TreeNode<int>* tree, int info) { TreeNode<int>* t; int cmp = info - *(tree->getInfo()); if( cmp < 0 ){ t = remove(tree->getLeft(), info); tree->setLeft( t ); } else if( cmp > 0 ){ t = remove(tree->getRight(), info); tree->setRight( t ); }  http://ecomputernotes.com
  • 17. C++ code for delete //two children, replace with inorder successor else if(tree->getLeft() != NULL && tree->getRight() != NULL ){ TreeNode<int>* minNode; minNode = findMin(tree->getRight()); tree->setInfo( minNode->getInfo() ); t = remove(tree->getRight(), *(minNode->getInfo())); tree->setRight( t ); }  http://ecomputernotes.com
  • 18. C++ code for delete //two children, replace with inorder successor else if(tree->getLeft() != NULL && tree->getRight() != NULL ){ TreeNode<int>* minNode; minNode = findMin(tree->getRight()); tree->setInfo( minNode->getInfo() ); t = remove(tree->getRight(), *(minNode->getInfo())); tree->setRight( t ); }  http://ecomputernotes.com
  • 19. C++ code for delete //two children, replace with inorder successor else if(tree->getLeft() != NULL && tree->getRight() != NULL ){ TreeNode<int>* minNode; minNode = findMin(tree->getRight()); tree->setInfo( minNode->getInfo() ); t = remove(tree->getRight(), *(minNode->getInfo())); tree->setRight( t ); }  http://ecomputernotes.com
  • 20. C++ code for delete //two children, replace with inorder successor else if(tree->getLeft() != NULL && tree->getRight() != NULL ){ TreeNode<int>* minNode; minNode = findMin(tree->getRight()); tree->setInfo( minNode->getInfo() ); t = remove(tree->getRight(), *(minNode->getInfo())); tree->setRight( t ); }  http://ecomputernotes.com
  • 21. C++ code for delete //two children, replace with inorder successor else if(tree->getLeft() != NULL && tree->getRight() != NULL ){ TreeNode<int>* minNode; minNode = findMin(tree->getRight()); tree->setInfo( minNode->getInfo() ); t = remove(tree->getRight(), *(minNode->getInfo())); tree->setRight( t ); }  http://ecomputernotes.com
  • 22. C++ code for delete else { // case 1 TreeNode<int>* nodeToDelete = tree; if( tree->getLeft() == NULL ) // will handle 0 children tree = tree->getRight(); else if( tree->getRight() == NULL ) tree = tree->getLeft(); else tree = NULL; delete nodeToDelete; } return tree; }  http://ecomputernotes.com
  • 23. C++ code for delete else { // case 1 TreeNode<int>* nodeToDelete = tree; if( tree->getLeft() == NULL ) // will handle 0 children tree = tree->getRight(); else if( tree->getRight() == NULL ) tree = tree->getLeft(); else tree = NULL; delete nodeToDelete; } return tree; }  http://ecomputernotes.com
  • 24. C++ code for delete else { // case 1 TreeNode<int>* nodeToDelete = tree; if( tree->getLeft() == NULL ) // will handle 0 children tree = tree->getRight(); else if( tree->getRight() == NULL ) tree = tree->getLeft(); else tree = NULL; delete nodeToDelete; } return tree; }  http://ecomputernotes.com
  • 25. C++ code for delete TreeNode<int>* findMin(TreeNode<int>* tree) { if( tree == NULL ) return NULL; if( tree->getLeft() == NULL ) return tree; // this is it. return findMin( tree->getLeft() ); }  http://ecomputernotes.com
  • 26. C++ code for delete TreeNode<int>* findMin(TreeNode<int>* tree) { if( tree == NULL ) return NULL; if( tree->getLeft() == NULL ) return tree; // this is it. return findMin( tree->getLeft() ); }  http://ecomputernotes.com
  • 27. C++ code for delete TreeNode<int>* findMin(TreeNode<int>* tree) { if( tree == NULL ) return NULL; if( tree->getLeft() == NULL ) return tree; // this is it. return findMin( tree->getLeft() ); }  http://ecomputernotes.com
  • 28. BinarySearchTree.h Let us design the BinarySearchTree class (factory). http://ecomputernotes.com
  • 29. BinarySearchTree.h #ifndef _BINARY_SEARCH_TREE_H_ #define _BINARY_SEARCH_TREE_H_ #include <iostream.h> // For NULL // Binary node and forward declaration template <class EType> class BinarySearchTree;  http://ecomputernotes.com
  • 30. BinarySearchTree.h #ifndef _BINARY_SEARCH_TREE_H_ #define _BINARY_SEARCH_TREE_H_ #include <iostream.h> // For NULL // Binary node and forward declaration template <class EType> class BinarySearchTree;  http://ecomputernotes.com
  • 31. BinarySearchTree.h template <class EType> class BinaryNode { EType element; BinaryNode *left; BinaryNode *right; BinaryNode( const EType & theElement, BinaryNode *lt, BinaryNode *rt ) : element( theElement ), left( lt ), right( rt ) { } friend class BinarySearchTree<EType>; };  http://ecomputernotes.com
  • 32. BinarySearchTree.h template <class EType> class BinaryNode { EType element; BinaryNode *left; BinaryNode *right; BinaryNode( const EType & theElement, BinaryNode *lt, BinaryNode *rt ) : element( theElement ), left( lt ), right( rt ) { } friend class BinarySearchTree<EType>; };  http://ecomputernotes.com
  • 33. BinarySearchTree.h template <class EType> class BinaryNode { EType element; BinaryNode *left; BinaryNode *right; BinaryNode( const EType & theElement, BinaryNode *lt, BinaryNode *rt ) : element( theElement ), left( lt ), right( rt ) { } friend class BinarySearchTree<EType>; };  http://ecomputernotes.com
  • 34. BinarySearchTree.h template <class EType> class BinaryNode { EType element; BinaryNode *left; BinaryNode *right; BinaryNode( const EType & theElement, BinaryNode *lt, BinaryNode *rt ) : element( theElement ), left( lt ), right( rt ) { } friend class BinarySearchTree<EType>; };  http://ecomputernotes.com
  • 35. BinarySearchTree.h template <class EType> class BinarySearchTree { public: BinarySearchTree( const EType& notFound ); BinarySearchTree( const BinarySearchTree& rhs ); ~BinarySearchTree( ); const EType& findMin( ) const; const EType& findMax( ) const; const EType& find( const EType & x ) const; bool isEmpty( ) const; void printInorder( ) const; http://ecomputernotes.com
  • 36. BinarySearchTree.h void insert( const EType& x ); void remove( const EType& x ); const BinarySearchTree & operator= ( const BinarySearchTree & rhs ); http://ecomputernotes.com
  • 37. BinarySearchTree.h private: BinaryNode<EType>* root; // ITEM_NOT_FOUND object used to signal failed finds const EType ITEM_NOT_FOUND; const EType& elementAt( BinaryNode<EType>* t ); void insert(const EType& x, BinaryNode<EType>* & t); void remove(const EType& x, BinaryNode<EType>* & t); BinaryNode<EType>* findMin(BinaryNode<EType>* t); BinaryNode<EType>* findMax(BinaryNode<EType>* t); BinaryNode<EType>* find(const EType& x, BinaryNode<EType>* t ); void makeEmpty(BinaryNode<EType>* & t); void printInorder(BinaryNode<EType>* t); }; #endif http://ecomputernotes.com

Editor's Notes

  1. Start lecture 16
  2. End of lecture 15
  3. End of lecture 16